﻿using System.Collections.Generic;
using System.Web;
using System.Text;

namespace pbvs.Utilities.Assets
{
    public class AssetsItemRegistrar
    {
        public const string StyleFormat = "<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />\r\n";
        public const string ScriptFormat = "<script src=\"{0}\" type=\"text/javascript\"></script>\r\n";

        private readonly string _format;
        private readonly IList<string> _items;

        public AssetsItemRegistrar(string format)
        {
            _format = format;
            _items = new List<string>();
        }

        public AssetsItemRegistrar Add(string url)
        {
            if (!_items.Contains(url))
            {
                _items.Add(url);
            }
            return this;
        }

        public IHtmlString Render()
        {
            StringBuilder sb = new StringBuilder();
            foreach (string item in _items)
            {
                sb.Append(string.Format(_format, item));
            }
            return new HtmlString(sb.ToString());
        }
    }
}